<html>
<!-- 
  Copyright 2010 Scott Logic Ltd.
  http://www.scottlogic.co.uk
  
  This file is part of Closure Charts.

  Closure Charts is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.

  Closure Charts is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.
  
  You should have received a copy of the GNU General Public License
  along with Closure Charts.  If not, see <http://www.gnu.org/licenses/>.
-->
<head>
<title>JavaScript Charting Unit Tests - DateTimeAxis</title>
<script type="text/javascript" src="../../../../../../../../closure-library/src/main/webapp/js/goog/base.js"></script>
<script type="text/javascript" src="../unitTestDependencies.js"></script>
<script>
    goog.require('goog.testing.jsunit');
    goog.require('goog.dom');
    goog.require('goog.date');

    goog.require('scottlogic.chart.rendering.DateTimeAxis');
</script>
</head>
<body>
<script>  
    // Clear the canvas after the charts have been tested
    function tearDown(){
        var canvas = goog.dom.$('canvas');
        canvas.innerHTML = '';
    }

    function testGetFirstLabelTick(){
        var min = new goog.date.UtcDateTime(2010, goog.date.month.AUG, 5, 15, 0, 0, 0);
        var max = new goog.date.UtcDateTime(2010, goog.date.month.AUG, 10, 15, 0, 0, 0);

        // years
        var yearsInterval = new goog.date.Interval(1, 0, 0, 0, 0, 0);
        var yearsInterval_result = new goog.date.UtcDateTime(2011, goog.date.month.JAN, 1, 0, 0, 0, 0);
        
        var axis = new scottlogic.chart.rendering.DateTimeAxis();
        axis.setMinimum(min);
        axis.setMaximum(max);
        axis.intervalStep = yearsInterval;

        assertEquals("Years interval", axis.normalize(yearsInterval_result), axis.getFirstLabelTick()); 


        // months
        var monthsInterval = new goog.date.Interval(0, 1, 0, 0, 0, 0);
        var monthsInterval_result = new goog.date.UtcDateTime(2010, goog.date.month.SEP, 1, 0, 0, 0, 0);
        
        var axis = new scottlogic.chart.rendering.DateTimeAxis();
        axis.setMinimum(min);
        axis.setMaximum(max);
        axis.intervalStep = monthsInterval;
        assertEquals("Months interval", axis.normalize(monthsInterval_result), axis.getFirstLabelTick());


        // days
        var daysInterval = new goog.date.Interval(0, 0, 1, 0, 0, 0);
        var daysInterval_result = new goog.date.UtcDateTime(2010, goog.date.month.AUG, 6, 0, 0, 0, 0);
        
        var axis = new scottlogic.chart.rendering.DateTimeAxis();
        axis.setMinimum(min);
        axis.setMaximum(max);
        axis.intervalStep = daysInterval;
        assertEquals("Days interval", axis.normalize(daysInterval_result), axis.getFirstLabelTick());


        // hours
        var hoursInterval = new goog.date.Interval(0, 0, 0, 1, 0, 0);
        var hoursInterval_result = new goog.date.UtcDateTime(2010, goog.date.month.AUG, 5, 15, 0, 0, 0);
        
        var axis = new scottlogic.chart.rendering.DateTimeAxis();
        axis.setMinimum(min);
        axis.setMaximum(max);
        axis.intervalStep = hoursInterval;
        assertEquals("Hours interval", axis.normalize(hoursInterval_result), axis.getFirstLabelTick());


        // minutes
        var minutesInterval = new goog.date.Interval(0, 0, 0, 0, 1, 0);
        var minutesInterval_result = new goog.date.UtcDateTime(2010, goog.date.month.AUG, 5, 15, 0, 0, 0);
        
        var axis = new scottlogic.chart.rendering.DateTimeAxis();
        axis.setMinimum(min);
        axis.setMaximum(max);
        axis.intervalStep = minutesInterval;
        assertEquals("Minutes interval", axis.normalize(minutesInterval_result), axis.getFirstLabelTick());
    }
   
</script>
<div id="canvas"></div>
</body>
</html>
